﻿using System;

namespace Mono.Cecil.Metadata
{
	// Token: 0x02000100 RID: 256
	internal sealed class UserStringHeapBuffer : StringHeapBuffer
	{
		// Token: 0x06000A42 RID: 2626 RVA: 0x0002E5E8 File Offset: 0x0002C7E8
		public override uint GetStringIndex(string @string)
		{
			uint position;
			bool flag = this.strings.TryGetValue(@string, out position);
			uint result;
			if (flag)
			{
				result = position;
			}
			else
			{
				position = (uint)this.position;
				this.WriteString(@string);
				this.strings.Add(@string, position);
				result = position;
			}
			return result;
		}

		// Token: 0x06000A43 RID: 2627 RVA: 0x0002E630 File Offset: 0x0002C830
		protected override void WriteString(string @string)
		{
			base.WriteCompressedUInt32((uint)(@string.Length * 2 + 1));
			byte b = 0;
			foreach (char c in @string)
			{
				base.WriteUInt16((ushort)c);
				bool flag = b == 1;
				if (!flag)
				{
					bool flag2 = c < ' ' || c > '~';
					if (flag2)
					{
						bool flag3 = c > '~' || (c >= '\u0001' && c <= '\b') || (c >= '\u000e' && c <= '\u001f') || c == '\'' || c == '-';
						if (flag3)
						{
							b = 1;
						}
					}
				}
			}
			base.WriteByte(b);
		}
	}
}
